﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CSTest
{
  class SymbolTable
  {
    IntPtr _obj;
    private SymbolTable(IntPtr obj)
    {
      _obj = obj;
    }

    public static SymbolTable ReadText(String filename)
    {
      IntPtr ptr = NativeMethods.ReadText(filename);
      return null;
    }

    class NativeMethods
    {
      internal const String dll = @"script-wrapper.dll";

      [DllImport(dll)]
      internal static extern IntPtr ReadText([MarshalAs(UnmanagedType.LPStr)] String filename);
    }
  }

  class Fst
  {
    IntPtr _obj;
    private Fst(IntPtr obj)
    {
      _obj = obj;
    }

    public String ArcType
    {
      get
      {
        IntPtr ptr = NativeMethods.ArcType(_obj);
        return Marshal.PtrToStringAnsi(ptr);
      }
    }

    public String FstType
    {
      get
      {
        IntPtr ptr = NativeMethods.FstType(_obj);
        return Marshal.PtrToStringAnsi(ptr);
      }
    }

    public static Fst Read(String filename)
    {
      IntPtr obj = NativeMethods.ReadFst(filename);
      return obj == null ? null : new Fst(obj);        
    }

    public bool Write(String filename)
    {
      NativeMethods.WriteFst(_obj, filename);
      return true;
    }    

    public static Fst Create(String arctype)
    {
      return new Fst(NativeMethods.CreateFst(arctype));
    }

    /// <summary>
    /// Create a VectorFst over the tropical semiring
    /// </summary>
    /// <returns></returns>
    public static Fst Create()
    {
      return new Fst(NativeMethods.CreateFst("standard"));
    }

    public static Fst Determinize(Fst fst)
    {
      return null;
    }
    
    class NativeMethods
    {
      internal const String dll = @"script-wrapper.dll";

      [DllImport(dll)]
      internal static extern IntPtr ArcType(IntPtr ptr);

      [DllImport(dll)]
      internal static extern IntPtr CreateFst([MarshalAs(UnmanagedType.LPStr)] String arctype);

      [DllImport(dll)]
      internal static extern IntPtr FstType(IntPtr ptr);

      [DllImport(dll)]
      internal static extern IntPtr ReadFst([MarshalAs(UnmanagedType.LPStr)] String arctype);

      [DllImport(dll)]
      internal static extern IntPtr WriteFst(IntPtr ptr, [MarshalAs(UnmanagedType.LPStr)]
        String filename);
    }
  }

  class Program
  {
    static void Main(string[] args)
    {    
    }
  }
}
